Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the Program.cs file to each module was the issue. #10

Merged

Conversation

amirhossein18121380
Copy link
Contributor

@amirhossein18121380 amirhossein18121380 commented Jun 10, 2024

Title: Added Extra API Layer for Better Organization

issue: #2

Description:
Added Program.cs to each module and implemented an extra API layer for better organization and maintainability. Also we could have achieved this with a single API layer, but this approach provides a clearer separation of concerns and easier integration with related libraries. I'm open to feedback and discussion on this change, and would appreciate any suggestions on how to improve the design.

@meysamhadeli
Copy link
Owner

meysamhadeli commented Jul 20, 2024

Title: Added Extra API Layer for Better Organization

Description: Added Program.cs to each module and implemented an extra API layer for better organization and maintainability. Also we could have achieved this with a single API layer, but this approach provides a clearer separation of concerns and easier integration with related libraries. I'm open to feedback and discussion on this change, and would appreciate any suggestions on how to improve the design.

Hi, Thanks for contribution :)
Please mention in your PR Description that this pull request is for implement this issue: #2

My goal is having 1 API Layer. And each module have own separate Program.cs. and with this approach each module with using Program.cs can host itself and we don't need to have separate API layer for each module and we need 1 API layer for coordination all of the module and having multiple API leads us to having separated microservices not modular monolith.

@amirhossein18121380
Copy link
Contributor Author

I deleted the extra API layer that I had added to each module before, and I added a Program.cs to each module (related class library). Now, each module can be hosted and executed independently.

However, I don't fully understand why we should add Program.cs to a class library (each module) if it cannot be hosted and run on its own. Wouldn't it be more efficient to keep an extra layer, such as a console application or API, that can be executed or hosted directly and reference the related class library? Am I right or wrong in my understanding?


<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove OutputType tag, it's not necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove OutputType tag, it's not necessary.

I applied the changes and I used top level statement like Api layer for program.cs but
for top-level statements in C# to work, the project must be configured as an executable. By removing this tag, the project will default to a class library, which does not support top-level statements.
The tag specifies whether the project is a library or an executable.
With the set to Exe, our top-level statements in Program.cs will work as intended.

Should I remove the tag or leave it as is?

Copy link
Owner

@meysamhadeli meysamhadeli Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here in Api layer we don't have any additional configuration and it can host as well. also you need to add Properties folder and add configuration json file for host like Api layer. You need the follow the configuration exactly like Api layer and also add Properties folder and afterward each module should host properly, Also you need to change project structure to Microsoft.NET.Sdk.Web:
Api.csproj

Copy link
Contributor Author

@amirhossein18121380 amirhossein18121380 Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed your instructions and added a Properties folder with a configuration JSON file to each module, similar to the API layer. I also changed the project structure to Microsoft.NET.Sdk.Web. However, I'm not sure if everything is correct?
for launchSetting i changed the port for each module. should all ports be exactly the same as api layer?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed your instructions and added a Properties folder with a configuration JSON file to each module, similar to the API layer. I also changed the project structure to Microsoft.NET.Sdk.Web. However, I'm not sure if everything is correct? for launchSetting i changed the port for each module. should all ports be exactly the same as api layer?

Thanks. Port should be different for each module. everything's seems good.

@meysamhadeli
Copy link
Owner

I deleted the extra API layer that I had added to each module before, and I added a Program.cs to each module (related class library). Now, each module can be hosted and executed independently.

However, I don't fully understand why we should add Program.cs to a class library (each module) if it cannot be hosted and run on its own. Wouldn't it be more efficient to keep an extra layer, such as a console application or API, that can be executed or hosted directly and reference the related class library? Am I right or wrong in my understanding?

If we have a separate Api for each module it provides complexity and we don't need it and we just need a simple Program.cs class for running independently each module. (it's also not very force, but it easier to have each module rune separately. But in the end modular monolith we have to one deployment).

/add launchSetting.json to each module and Updated ports
/change modules Sdk to "Microsoft.NET.Sdk.Web"
/remove unnecessary tags in .csproj
Copy link
Owner

@meysamhadeli meysamhadeli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contribution :)

@meysamhadeli meysamhadeli merged commit 2a7334e into meysamhadeli:main Jul 24, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants